#ifndef __APP_CTRL_H
#define __APP_CTRL_H
#include "main.h"
#include "bsp_can.h"
#include "bsp_tim.h"
#include "drv_gm6020.h"
#include "drv_dm.h"
#include "drv_nrf24l01.h"
#include "drv_algo.h"
#include "drv_dji.h"

extern uint32_t app_raw_data[]; // 发送的机器角度值
extern uint16_t app_send_data[];
extern float app_gravity_vel_data[2];

extern float app_watch_angles[];
extern unsigned int app_watch_int[];

extern motor_gm6020_t motor_1;
extern motor_dm_t motor_2;
extern motor_dm_t motor_3;

/* 1. 初始化和工具函数 */
uint8_t App_Init_Enable(void);
uint8_t App_MainLoop(void);
float App_Uint2Float(uint16_t x_int, float x_min, float x_max, uint8_t bits);
int App_Float2Uint(float x_float, float x_min, float x_max, uint8_t bits);
float App_Int2Float(int x_int, float x_min, float x_max, int bits);

/* 2. 任务一 发送收集的角度数据 */
uint8_t App_UpdateSendData(void);
uint8_t App_SendData(void);
uint8_t App_NormalizeAndSendData(void);
uint8_t App_GetFloatAngle(void);

/* 3. 任务二 重力补偿 */
void App_GravityPID_Init(void);
uint8_t App_UpdateGravityData(void);
uint8_t App_Gravity_Compensation(uint8_t tx_id);
void App_SetGravityTargetVel(uint8_t motor_id, float target_velocity);

#endif
